-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type parameter variance of enum #28
Type parameter variance of enum #28
Conversation
Interesting... but I wonder, does this actually solve any problem? I can see your reasoning from a typing theory point of view, but I'm not convinced that the additional complexity actually comes with any advantage. |
Of course, this has advantages. I added an actual example. |
To clarify, this is the failing case: import haxe.ds.Option;
class Main {
static public function main() {
var optionFloat:Option<Float>;
var optionInt = Option.Some(1);
optionFloat = optionInt;
}
} Your direct assignment works already due to top-down inference. And yes I can see the point here. Given that enum arguments are read-only, covariance could be allowed. @ncannasse: Any opinions? |
The problem is that type parameters variance depends on the way it's used.
In this case |
If you mean this
However,
This is the list of "A is B" relation:
|
We have decided to reject this proposal in our haxe-evolution meeting yesterday. We concluded that we should approach this in a broader scope, not just for enum, but also in other cases, especially with "read-only" types (e.g. HaxeFoundation/haxe#9611). |
This proposes new variance rule for enum.
Rendered version